﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B.S.XZYData.ErrorCode
{
    /// <summary>
    /// 统一包装类
    /// </summary>
    /// <typeparam name="T">虚拟返回类型</typeparam>
    public class ApiResult<T>
    {
        /// <summary>
        /// 信息
        /// </summary>
        public string? Msg { get; set; }
        /// <summary>
        /// 状态码
        /// </summary>
        public ApiEnum? Code { get; set; }
        /// <summary>
        /// 数据
        /// </summary>
        public T? Data { get; set; }

        /// <summary>
        /// 成功返回
        /// </summary>
        /// <param name="data">数据</param>
        /// <returns></returns>
        public static ApiResult<T> Success(T data)
        {
            return new ApiResult<T>
            {
                Code = ApiEnum.Success,
                Msg = "操作成功",
                Data = data
            };
        }

        /// <summary>
        /// 失败返回
        /// </summary>
        /// <param name="message">错误信息</param>
        /// <returns></returns>
        public static ApiResult<T> Error(string message)
        {
            return new ApiResult<T>
            {
                Code = ApiEnum.Error,
                Msg = message,
                Data = default(T)
            };
        }
    }
}
